package com.atguigu.srb.rabbitutil.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description:
 * @Author: Gavin
 * @Date: 7/23/2023 4:43 PM
 */
@Service
@Slf4j
public class MQService {
    @Resource
    AmqpTemplate amqpTemplate;
    public boolean sendMessage(String exchange,String routingKey,Object message){
        log.info("发送消息......");
        amqpTemplate.convertAndSend(exchange,routingKey,message);
        //如果发送消息的过程中有异常,那么会在上面的方法中抛出,没有异常的话就直接返回true了
        return true;
    }
}
